package com.spr.gw.controller;

import com.spr.gw.common.ResultBean;
import com.spr.gw.entity.Message;
import com.spr.gw.entity.VO.MessageVo;
import com.spr.gw.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.transform.Result;
import java.util.List;

/**
 * Created by lsy
 * on 2017/10/28 14:12.
 */
@Controller
public class FrontContentController {


    @Autowired
    private MessageService messageService;

    /**
     * 获得一个栏目一个消息的内容
     * @param categoryId
     * @return
     */
    @RequestMapping("/getContent/{categoryId}")
    @ResponseBody
    public ResultBean findOnePageContent(@PathVariable(value = "categoryId") Integer categoryId){
        Message message = messageService.findOnePageContent(categoryId);
        return ResultBean.createBySuccess(message);
    }

    @RequestMapping("/getContentPage/{categoryId}")
    @ResponseBody
    public ResultBean findContentPage(@PathVariable(value = "categoryId") Integer categoryId){
        List<MessageVo> messages = messageService.findAllMessageByCategoryId(categoryId);
        return ResultBean.createBySuccess(messages);
    }
}
